/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gov.nist.ssd.swqb.core.files;

import gov.nist.ssd.swqb.core.ConfigFileManager;

/**
 *
 * @author Benjamin Herbomez
 */
public class OptionManager extends PairFileManager{
    
    public OptionManager(ConfigFileManager fm){
        super(fm);
        this.fileName = "options";
        init();
    }
    
    
    public String getOption(String key){
        if(this.pairs.containsKey(key))
            return this.pairs.get(key);
        return null;
    }
    
    /**
     * 
     * @param key
     * @return correct int or null if cast fails 
     */
    public Integer getOptionAsInt(String key){
        if(this.pairs.containsKey(key)){
            try{
                return Integer.valueOf(this.pairs.get(key));
            }
            catch(NumberFormatException ex){}
        }
        return null;
    }
    
    /**
     * 
     * @param key
     * @return correct int or null if cast fails 
     */
    public Float getOptionAsFloat(String key){
        if(this.pairs.containsKey(key)){
            try{
                return Float.valueOf(this.pairs.get(key));
            }
            catch(NumberFormatException ex){}
        }
        return null;
    }

    public void setOption(String option, String value) {
        this.pairs.put(option, value);
        this.save();
    }
}
